/*
 * BanBu_HeaderView
 * @description 本文件提供对话界面显示对方资料的功能view
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供对话界面显示对方资料的功能view
 */

#import "BanBu_HeaderView.h"
#import <QuartzCore/QuartzCore.h>
#define x 80
@interface BanBu_HeaderView()

-(void)initEvery;

@end



@implementation BanBu_HeaderView
@synthesize headImage=_headImage,nameAndsex=_nameAndsex,starLabel=_starLabel,nameLabel=_nameLabel,nextButton=_nextButton,nextView=_nextView,chat=_chat,ageLabel=_ageLabel;

- (void)dealloc
{
    _headImage = nil;
    _ageLabel = nil;
    _bgView = nil;
    _nameAndsex = nil;
    _nameLabel = nil;
    _starLabel = nil;
    _vipImageView = nil;
    _verify = nil;
    _nextButton = nil;
    [super dealloc];
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        // Initialization code
    }
    return self;
}

-(BanBu_HeaderView *)initWithDelegate:(BanBu_ChatViewController *)table Selector:(SEL)nextView Frame:(CGRect)rect TableView:(UITableView *)tablet
{
    self=[super init];
    
    if(self)
    {
        self.backgroundColor=[UIColor colorWithRed:255.0/255 green:250.0/255 blue:240.0/255 alpha:1.0];
      
        self.chat=table;
        
        self.frame=rect;
        
        _nextView=nextView;
        
        [self initEvery];
    
        // 加一个点击的手势
        
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushNext:)];
        
        tap.numberOfTapsRequired=1;
        
        [self addGestureRecognizer:tap];
        
        [tap release];
        
        return self;
    }

    return nil;
}

-(void)pushNext:(UITapGestureRecognizer *)tap
{
    if(_nextView)
    {
    [_chat performSelector:_nextView];

    }

}
-(void)initEvery
{
    _bgView = [[UIView alloc]initWithFrame:self.frame];
    _bgView.backgroundColor = [UIColor grayColor];
    _bgView.alpha = 0.2;
    [self addSubview:_bgView];
    [_bgView release];
    
    _headImage = [[UIImageView alloc] initWithFrame:CGRectMake(5,5, 54, 54)];
    
    //头像
    _headImage.contentMode = UIViewContentModeScaleAspectFit;
    _headImage.layer.cornerRadius = 27.0f;
    _headImage.layer.masksToBounds = YES;
    [self addSubview:_headImage];
    [_headImage release];
    
    //VIP图标
    _vipImageView = [[UIImageView alloc] initWithFrame:CGRectMake(4, 4, 56, 58)];
    [self addSubview:_vipImageView];
    [_vipImageView release];
    

    //姓名
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(63,5, 235, 25)];
    
    _nameLabel.textAlignment = kTextAlignmentLeft;
    _nameLabel.backgroundColor = [UIColor clearColor];
    _nameLabel.font = [UIFont systemFontOfSize:13];
    _nameLabel.textColor = [UIColor whiteColor];
    [self addSubview:_nameLabel];
    [_nameLabel release];
    
    //性别
    _nameAndsex = [[UIImageView alloc]initWithFrame:CGRectMake(68, 42, 13, 13)];
    [self addSubview:_nameAndsex];
    [_nameAndsex release];
    
    //视频认证图标
    NSString *verifypath = [[NSBundle mainBundle] pathForResource:@"verify_card" ofType:@"png"];
    _verify = [[UIImageView alloc]initWithImage:[UIImage imageWithContentsOfFile:verifypath]];
    _verify.frame = CGRectMake(100, 44, 15, 10);
    _verify.hidden = YES;
    [self addSubview:_verify];
    [_verify release];
    
    //星座
    _starLabel = [[UILabel alloc] initWithFrame:CGRectMake(63+15+40,35, 75, 25)];
    _starLabel.backgroundColor=[UIColor clearColor];
    _starLabel.textAlignment=kTextAlignmentCenter;
    _starLabel.font = [UIFont systemFontOfSize:13];
    _starLabel.textColor = [UIColor whiteColor];
    [self addSubview:_starLabel];
    [_starLabel release];
    
     // 年龄的label
    _ageLabel=[[UILabel alloc]initWithFrame:CGRectMake(205, 35, 50, 25)];
    _ageLabel.backgroundColor = [UIColor clearColor];
    _ageLabel.font = [UIFont systemFontOfSize:13];
    _ageLabel.textAlignment = kTextAlignmentLeft;
    _ageLabel.textColor = [UIColor whiteColor];
    [self addSubview:_ageLabel];
    [_ageLabel release];
    
    // 右边的小箭头
    _nextButton = [UIButton buttonWithType: UIButtonTypeCustom];
    [_nextButton setBackgroundImage:[UIImage imageNamed:@"profileios.png"] forState:UIControlStateNormal];
    [_nextButton addTarget:self action:@selector(pushNext:) forControlEvents:UIControlEventTouchUpInside];
    _nextButton.frame = CGRectMake(300, 25, 10, 16);
    [self addSubview:_nextButton];
    
    // uilabel
    UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.bounds.size.height, 320, 1)];
    lineLabel.backgroundColor=[UIColor grayColor];
    lineLabel.alpha=.1;
    [self addSubview:lineLabel];
    [lineLabel release];
}

-(void)setHeadImaget:(NSString *)headImage
{
     [_headImage setImageWithURL:[NSURL URLWithString:headImage] placeholderImage:[UIImage imageNamed:@"default.png"] andType:1];
}

-(void)setNameLabelt:(NSString *)name
{
    _nameLabel.text=name;
}

-(void)setAgeAndSext:(NSString *)ageAndsex verify:(BOOL)verify
{
    [_verify setHidden:!verify];
    if (!verify)
    {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"verify_normal" ofType:@"png"];
        _vipImageView.image =  [UIImage imageWithContentsOfFile:path];
        
    }
    else
    {
        
        NSString * verifySource = [NSString stringWithFormat:@"verify_%@",ageAndsex];
        NSString *path = [[NSBundle mainBundle] pathForResource:verifySource ofType:@"png"];
        _vipImageView.image =  [UIImage imageWithContentsOfFile:path];
    }
    
    NSString *sexpath = [[NSBundle mainBundle] pathForResource:ageAndsex ofType:@"png"];
    _nameAndsex.image = [UIImage imageWithContentsOfFile:sexpath];
    
}

-(void)setStar:(NSString *)star
{
    _starLabel.text=star;
}

-(void)setAge:(NSString *)age
{
    _ageLabel.text=age;
}


-(void)setVIPFlag:(BOOL)_flag
{
    if (_flag)
    {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"verify_vip" ofType:@"png"];
        _vipImageView.image =  [UIImage imageWithContentsOfFile:path];
    }
}

- (void)setVerify:(BOOL)_flag
{
    _verify.hidden = _flag;
}

@end
